﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;
using System.Web;

namespace Yuanlin.Business
{
    public class VisitBusinessInfo : YuanlinUserControl,
        IReplyConverter<BusinessInfoReply, GetListOperation>
    {
        protected Repeater list;
        protected HtmlControl moreDiv;
        private EntityList businessInfos;
        private int entityId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.BusinessInfoId);
        private int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);
        public string greenNum = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.GreenNum);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetBusinessInfoListRequest(this, UserIdFromGreenNum, entityId, categoryId,0,6));
        }

        private void BindData()
        {
            if (list == null)
            {
                return;
            }
            EntityList temp = new EntityList()  ;
            if (businessInfos.Count <= 5)
            {
                temp = businessInfos;
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    temp.Add(businessInfos[i]);
                }
                moreDiv.Visible = true;
            }
            list.DataSource = temp;
            list.DataBind();
        }


        #region IReplyConverter<BusinessInfoReply,GetListOperation> Members

        public void ConvertReply(BusinessInfoReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                businessInfos = reply.EntityList;
                if (!Page.IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
